package com.fivefu.core.hik.services.impl;

import com.fivefu.core.hik.entity.DbHikInterface;
import com.fivefu.core.hik.mapper.DbHikInterfaceMapper;
import com.fivefu.core.hik.services.DbHikInterfaceService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * <p>
 * 海康接口同步 服务实现类
 * </p>
 *
 * @author DELL
 * @since 2022-06-30
 */
@Service
public class DbHikInterfaceServiceImpl extends ServiceImpl<DbHikInterfaceMapper, DbHikInterface> implements DbHikInterfaceService {

    /**
     * 添加请求记录
     * @param interfaceUrl 请求接口地址
     * @param interfaceParam 请求参数
     * @param starttime 请求参数_开始时间
     * @param endtime 请求参数_结束时间
     * @param interfaceTypeCode 接口类型标识
     * @return 请求记录编号
     */
    @Override
    public Long insertHikInterface(String interfaceUrl, String interfaceParam, LocalDateTime starttime, LocalDateTime endtime, String interfaceTypeCode){
        DbHikInterface hikInterface = new DbHikInterface();
        hikInterface.setInterfaceUrl(interfaceUrl);
        hikInterface.setInterfaceParam(interfaceParam);
        hikInterface.setStarttime(starttime);
        hikInterface.setEndtime(endtime);
        hikInterface.setInterfaceTypeCode(interfaceTypeCode);
        hikInterface.setCreatedTime(LocalDateTime.now());
        hikInterface.setIsDelete(0);
        baseMapper.insert(hikInterface);
        return hikInterface.getId();
    }

    /**
     * 变更请求记录响应结果
     * @param interfaceID 请求记录编号
     * @param interfaceResult 响应结果
     * @param interfaceStatus 请求是否成功(0:否,1:是)
     */
    @Override
    public void updateHikInterfaceStatus(Long interfaceID,String interfaceResult,Integer interfaceStatus){
        DbHikInterface hikInterface = new DbHikInterface();
        hikInterface.setId(interfaceID);
        hikInterface.setInterfaceResult(interfaceResult);
        hikInterface.setInterfaceStatus(interfaceStatus);
        hikInterface.setUpdatedTime(LocalDateTime.now());
        baseMapper.updateById(hikInterface);
    }

}
